package com.fund.client.controller;

import com.fund.client.pojo.dto.ClientPageDTO;
import com.fund.client.pojo.dto.Questionnaire;
import com.fund.client.pojo.entity.Client;
import com.fund.client.pojo.vo.ClientVO;
import com.fund.client.service.ClientService;
import com.fund.common.pojo.PageResult;
import com.fund.common.pojo.Result;
import com.fund.common.retention.ParamParse;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/client")
public class ClientController {

    @Autowired
    ClientService clientService;

    @PostMapping
    public Result<Boolean> openAccount(@RequestBody Client client) {
        return clientService.openAccount(client);
    }

    @GetMapping("/page")
    public Result<PageResult<ClientVO>> getAllClient(@ParamParse ClientPageDTO clientPageDTO) {
        return clientService.getPage(clientPageDTO);
    }

    @DeleteMapping("/{id}")
    public Result<Boolean> deleteClient(@PathVariable Long id) {
        return Result.success(clientService.removeById(id));
    }

    @PostMapping("/questionnaire")
    public Result<Boolean> fillQuestionnaire(@RequestBody Questionnaire questionnaire) {
        return clientService.fillQuestionnaire(questionnaire);
    }

    @GetMapping("/code")
    public Result<List<ClientVO>> fuzzySearch(String clientQuery) {
        return clientService.findByCode(clientQuery);
    }

    @GetMapping
    public Result<ClientVO> findById(Long id) {
        return clientService.findById(id);
    }
}
